#include "../../framework/framework.h"
#include "../inc/xIndex.h"
#include "../inc/xDevice.h"
#include "../inc/xMedia.h"
namespace Sky
{


	TUint xIndex::ms_Usage = D3DUSAGE_DYNAMIC;
	D3DFORMAT xIndex::ms_Format = D3DFMT_INDEX32;
	D3DPOOL xIndex::ms_Pool = D3DPOOL_DEFAULT;
	xIndex::xIndex()
	{
		Initialise();
	}

	xIndex::~xIndex()
	{
		Finalise();
	}

	TResult xIndex::onCreate( xDxApp* app )
	{
		return XE_OK;
	}

	TResult xIndex::onDelete( xDxApp* app )
	{
		Finalise();
		return XE_OK;
	}

	TResult xIndex::onCreate( xDevice* device )
	{
		TResult hr;
		if(vNull != m_Res)
		{
			onDelete(device);
		}
		hr = device->getDevice9()->CreateIndexBuffer(m_Length,m_Usage,m_Format,m_Pool,&m_Res,vNull);
		if(FAILED(hr)){
			myDx_Trace_hr0(M,hr,"xIndex::onCreate() failed");
			return XE_APICALL;
		} // if(FAILED(hr))
		return XE_OK;
	}

	TResult xIndex::onReset( xDevice* device )
	{
		if(vNull != m_Res)return XE_OK;
		return onCreate(device);
	}

	TResult xIndex::onLost( xDevice* device )
	{
		return onDelete(device);
	}


	TResult xIndex::onDelete( xDevice* device )
	{
		SAFE_RELEASE(m_Res);
		return XE_OK;
	}	

	TVoid xIndex::Initialise()
	{
		m_Usage = ms_Usage;
		m_Format = ms_Format;
		m_Pool = ms_Pool;
	}

	TVoid xIndex::Finalise()
	{

	}
}
